//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package com.goldhuman.Common;

import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.util.HashMap;

public final class Conf {
    private static Conf instance = new Conf();
    private File conffile;
    private long mtime;
    private HashMap<String, HashMap<String, String>> confhash = new HashMap();
    private String charset = new String("GBK");

    private Conf() {
    }

    private void parse(BufferedReader br) throws IOException {
        String section = null;
        HashMap<String, String> sechash = new HashMap();
        this.confhash.clear();

        while(br.ready()) {
            String line = br.readLine().trim();
            if (line.length() != 0) {
                char c = line.charAt(0);
                if (c != '#' && c != ';') {
                    if (c == '[') {
                        line = line.substring(1, line.indexOf(93)).trim();
                        if (section != null) {
                            this.confhash.put(section, sechash);
                            sechash = new HashMap();
                        }

                        section = line;
                    } else {
                        String[] key_value = line.split("=", 2);
                        sechash.put(key_value[0].trim(), key_value[1].trim());
                    }
                }
            }
        }

        if (section != null) {
            this.confhash.put(section, sechash);
        }

    }

    private void reload() {
        try {
            for(long last = this.conffile.lastModified(); last != this.mtime; last = this.conffile.lastModified()) {
                this.mtime = last;
                URL url = this.conffile.toURI().toURL();
                BufferedReader br = new BufferedReader(new InputStreamReader(url.openStream(), this.charset));
                this.parse(br);
                br.close();
            }
        } catch (Exception var5) {
            var5.printStackTrace();
        }

    }

    public synchronized String find(String section, String key) {
        HashMap<String, String> sechash = (HashMap)this.confhash.get(section);
        if (sechash != null) {
            String val = (String)sechash.get(key);
            if (val != null) {
                return new String(val);
            }
        }

        return new String();
    }

    public synchronized void put(String section, String key, String val) {
        HashMap<String, String> sechash = (HashMap)this.confhash.get(section);
        if (sechash == null) {
            sechash = new HashMap();
            this.confhash.put(section, sechash);
        }

        sechash.put(key, val);
    }

    public static synchronized Conf GetInstance(String filename, String charset) {
        if (charset != null) {
            instance.charset = charset;
        }

        File file = new File(filename);
        if (file.isFile()) {
            instance.conffile = file;
            instance.reload();
        }

        return instance;
    }

    public static synchronized Conf GetInstance(URL url, String charset) {
        try {
            if (charset != null) {
                instance.charset = charset;
            }

            BufferedReader br = new BufferedReader(new InputStreamReader(url.openStream(), instance.charset));
            instance.parse(br);
            br.close();
        } catch (Exception var3) {
            var3.printStackTrace();
        }

        return instance;
    }

    public static synchronized Conf GetInstance() {
        return instance;
    }

    public static void main(String[] args) {
        GetInstance((String)args[0], (String)null);
        System.out.println(GetInstance().find(args[1], args[2]));
    }
}
